package org.jeecg.modules.demo.crm.service.impl;

import org.jeecg.modules.demo.crm.entity.CBankInfo;
import org.jeecg.modules.demo.crm.entity.CContractingUnit;
import org.jeecg.modules.demo.crm.entity.CInvoiceInfo;
import org.jeecg.modules.demo.crm.mapper.CContractingUnitMapper;
import org.jeecg.modules.demo.crm.mapper.CInvoiceInfoMapper;
import org.jeecg.modules.demo.crm.service.ICContractingUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 发包单位
 * @Author: jeecg-boot
 * @Date:   2025-05-28
 * @Version: V1.0
 */
@Service
public class CContractingUnitServiceImpl extends ServiceImpl<CContractingUnitMapper, CContractingUnit> implements ICContractingUnitService {

    @Autowired
    CInvoiceInfoMapper cInvoiceInfoMapper;

    @Autowired
    CContractingUnitMapper cContractingUnitMapper;

    @Override
    public void instalData(CContractingUnit cContractingUnit) {
        List<CInvoiceInfo> bankInfoList = cInvoiceInfoMapper.findByRelevanceId(cContractingUnit.getId());
        cContractingUnit.setId(null);
        cContractingUnitMapper.insert(cContractingUnit);
        for (CInvoiceInfo invoiceInfo : bankInfoList) {
            invoiceInfo.setRelevanceId(cContractingUnit.getId());
            cInvoiceInfoMapper.updateById(invoiceInfo);
        }
    }
}
